package com.example.program.utils

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View

//给View扩展一个方法实现放大缩小的动画

fun View.startScaleAnim(from: Float,to: Float, duration: Long = 500, onEnd:()->Unit = {}){
    val xAnim = ObjectAnimator.ofFloat(this,"scaleX",from,to).apply {
        this.duration = 500
    }
    val yAnim = ObjectAnimator.ofFloat(this,"scaleY",from,to).apply {
        this.duration = 500
    }
    AnimatorSet().apply {
        playTogether(xAnim,yAnim)
        addListener(object : Animator.AnimatorListener{
            override fun onAnimationStart(animation: Animator) {
                TODO("Not yet implemented")
            }

            override fun onAnimationEnd(animation: Animator) {
                onEnd()//通过高阶函数回调动画结束的事件
            }

            override fun onAnimationCancel(animation: Animator) {
                TODO("Not yet implemented")
            }

            override fun onAnimationRepeat(animation: Animator) {
                TODO("Not yet implemented")
            }

        })
        start()
    }
}